<%--
Created by IntelliJ IDEA.
User: CMCC
Date: 2016/8/26
Time: 16:12
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="css/login.css"/>
    <script type="text/javascript" src="js/jquery-3.1.0.min.js"></script>
    <script type="text/javascript" src="js/mui.min.js"></script>
    <script type="text/javascript" src="js/security.min.js"></script>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/md5.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
    <title>登录</title>
    <script type="text/javascript">
        mui.ready(function () {
            console.debug("ready for doing");
            var hosturl = "http://"+ window.location.host + "/"+ window.location.pathname.split('/')[1];
            var modulus = "009a082e53695b61cbdbd4dd5dd374a87b842d82660843ed79047868301c6f65647e5bcffcae39d81be2d96d46981d8d92d6ee344969f3dab0a763e84989296f5b3a7975ec20d19c815794760a1f8c203effa52ca465f92a639181f2f3097cb8f1402dc735ebc0466fc80675f54efbb63219980f39e8a7c4374d3877a8cb8e187d", exponent = "010001";

//				mui.ajax("http://120.27.236.48:8080/com.spring/user/login", {
//					data: null,
//					dataType: 'json', //服务器返回json格式数据
//					type: 'get', //HTTP请求类型
//					timeout: 10000, //超时时间设置为10秒；
//					success: function(data) {
//						//服务器返回响应，根据响应结果，分析是否登录成功；
//						console.debug("data : " + JSON.stringify(data));
//						modulus = data.modulus;
//						exponent = data.exponent;
//
//					},
//					error: function(xhr, type, errorThrown) {
//						//异常处理；
//						console.log(type);
//					}
//				});
            document.getElementById("login_submit").addEventListener("click", function () {
                var uName = $("#username").val();
                var pwd = $("#password").val();
                var isadmin = document.getElementById("isadmin");
                console.debug("username:" + uName + ",password:" + pwd);
                //生成加密key，然后对pwd明文密码做加密，结果放入encryptedPwd
                var key = RSAUtils.getKeyPair(exponent, '', modulus);
                var encryptedPwd = RSAUtils.encryptedString(key, pwd);
                var md5Pwd = hex_md5(pwd+"cmaracc");
                console.log("encryptedPwd:" + encryptedPwd);
                //请求登录接口,post，带明文账号和加密后的密码
                if (!isadmin.checked) {
                    mui.ajax(hosturl+"/user/login", {
                        data: {
                            "userName": uName,
                            "password": md5Pwd
                        },
                        dataType: "json",
                        type: "post",
                        timeout: 10000,
                        success: function (data) {
                            if (data.status == "error") {
                                layer.msg(data.description, function(){
                                });
//                                alert(data.description);
                            } else {
                                window.location.href = hosturl+'/contractInfo.jsp';

                            }

                        },
                        error: function (xhr, type, errorThrown) {
                            console.log(type);
                        }
                    });
                } else {
                     console.log(hosturl);
                    mui.ajax(hosturl+"/admin/login", {
                        data: {
                            "adminName": uName,
                            "adminPassword": md5Pwd
                        },
                        dataType: "json",
                        type: "post",
                        timeout: 10000,
                        success: function (data) {
                            if (data.status == "error") {
                                layer.msg(data.description, function(){
                                });
                            } else {
                                window.location.href = hosturl+'/contractMana.jsp';

                            }

                        },
                        error: function (xhr, type, errorThrown) {
                            console.log(type);
                        }
                    });
                }


            });
        });

        //			window.onload = function() {
        //				var oLoginSubmit = document.getElementById('login_submit');
        //				oLoginSubmit.onclick = function() {
        //					window.location.href = 'contractInfo.html';
        //				};
        //			}
    </script>

</head>

<body>
<!--<div class="container">-->
<!--<form action="" class="from-signin">-->
<!--<h2 class="form-signin-heading">合同管理系统</h2>-->
<!--<label></label>-->
<!--</form>-->
<!--</div>-->
<div class="loginBackground">
    <table class="login-table">
        <tr>
            <td>
                <div class="max-logo">
                    <label class="max-logo"><br/>
                        <br/>
                        合同管理系统</label>

                </div>
            </td>
            <td>
                <div class="login-box">
                    <div class="form-group">
                        <label class="login-font">用户名：</label>
                        <input class="login-input" id="username"/><br/>
                    </div>
                    <div class="form-group">
                        <label class="login-font">密&nbsp;&nbsp;&nbsp;&nbsp;码：</label>
                        <input class="login-input" id="password" type="password"/><br/>
                        <div class="checkbox">
                            <label><input id="isadmin" type="checkbox" value="">管理员</label>
                        </div>
                    </div>
                    <div class="form-group">
                        <input type="button" id="login_submit" class="reg-btn" value="登录"/>
                    </div>

                </div>
            </td>
        </tr>

    </table>

</div>
</body>

</html>